package com.dingding.nettyserver.common.handler;

import com.aliyun.openservices.ons.api.Action;
import com.dingding.common.core.push.pushmsg.TcpPushPack;
import com.dingding.nettyserver.core.session.SessionManager;
import com.dingding.nettyserver.core.util.LogKit;
import com.google.protobuf.MessageLite;

/**
 * @Description 推送的抽象类
 * @author fengshuonan
 * @date 2016年12月1日 下午5:42:35
 */
public abstract class AbstractPushHandler {

	protected <T extends MessageLite> Action pushToClient(TcpPushPack tcpPushPack, T t) {
		//获取客户端的用户id并判断当前用户是否存在于会话管理器的集合中
		if (tcpPushPack != null && SessionManager.isOnlineUser(tcpPushPack.getTargetUserId())) {
			
			//给用户发送信息
			SessionManager.sendMessage(tcpPushPack.getTargetUserId(), tcpPushPack.getBizType(),
					tcpPushPack.getModular(), tcpPushPack.getCmd(), t);
			
			LogKit.info("推送给在线客户端消息！服务类型： " + tcpPushPack.getBizType() + 
					",模块号： " + tcpPushPack.getModular() + 
					",命令号号： " + tcpPushPack.getCmd() + 
					",用户id：" + tcpPushPack.getTargetUserId());
			return Action.CommitMessage;
		} else {
			LogKit.info("推送给在线客户端消息时，用户不在线！");
			return Action.CommitMessage;
		}
	}

}
